﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using KTOP.Core.Domain;
using KTOP.Core.Domain.Matrix;
using KTOP.Core.Formatters;
using KTOP.Core.Netlists;

namespace KTOP.Homeworks.Hw6.Logics
{
    class HwCreationSession
    {
        private readonly Netlist _netlist;
        private RMatrix _rMatrix;
        private TextWriter _tw;

        public HwCreationSession(Netlist netlist, TextWriter tw)
        {
            _netlist = netlist;
            _tw = tw;
        }

        public void Do()
        {
            _rMatrix = RMatrix.CreateFromNetlist(_netlist);

            FormatResults(_tw);

        }

        void FormatResults(TextWriter tw)
        {
            var matrixFormatter = new MatrixFormatter();
            var netlistFormatter = new NetlistFormatter();
            var textTableFormatter = new TextTableFormatter();

            netlistFormatter.Format(_netlist, "source netlist", tw);
            tw.WriteLine();

            matrixFormatter.Format(_rMatrix, "r matrix", tw);
            tw.WriteLine();

            _tw.WriteLine("only r matrix is built");

        }

    }
}
